/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


(function($){
    
    /**
     * Bind events in an element.
     * Overload 1 - accepts two argument
     *  @param arg1 - sizzle that owns the binding
     *  @param arg2 - object that contain(s) the methods to bind. if undefined all methods in arg1 is binded.
     *  
     */
    
    
    
    $.fn.bind_methods = function(arg1,arg2){
                
        //break if arg1 or arg2 is undefined
        if(arg1 == undefined)return;
        
        // equate each to a variable in case there will be another load.
        var sizzle, json, list, load = 1;
        
        return this.each(function(){
            var $this = $(this);
            
            $.overload(
                [function(){
                    
                    sizzle = $this;
                    json = arg1;
                    list = arg2;
                    
                }],load);
            
            $.each(json,function(key,val){
                if(arg2 == null && typeof(val) == "function"){
                    
                    sizzle.bind(key,val);
                    
                }else if($.inArray(key,list) != -1){
                    
                    sizzle.bind(key,val);
                    
                }
                
            });
        })
    }
    
    // Overload 2
    
})(jQuery)